/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.windesheim.archdemo;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;
import nl.windesheim.archdemo.presentationmodel.MainFramePresenter;
import nl.windesheim.archdemo.view.MainFrame;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * @author reindert
 */
public class ArchDemo {

    private final static Logger LOG = Logger.getLogger(ArchDemo.class.getName());
    private static ApplicationContext context;

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
        } catch (Exception ex) {
            LOG.log(java.util.logging.Level.SEVERE, null, ex);
        }

        try {
            // FIXME: app doesn;t always stop
            // TODO: spring shutdown on exit
            // TODO: handle exceptions in spring startup
            context = new ClassPathXmlApplicationContext("applicationContext.xml");
        } catch (Exception ex) {
            LOG.log(Level.SEVERE, null, ex);
            System.exit(1);
        }


        // TODO: add GUI for inserting data in DB
        // TODO: wishlist: input DB type, DB url, usr, pwd
        // TODO: test for db connection - if it does not work: let user input connection properties
        
        /*try {
        ((BasicDataSource)context.getBean("dataSource")).getConnection();
        } catch (SQLException ex) {
        Logger.getLogger(ArchitectureDemoApp.class.getName()).log(Level.SEVERE, null, ex);
        }*/

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                MainFramePresenter pres = new MainFramePresenter();
                MainFrame mainFrame = new MainFrame(pres);
                pres.setView(mainFrame);
                mainFrame.setVisible(true);
            }
        });
    }
}
